/*--------------------劳务模块.人员管理--ly-----------------*/
/*--------------------劳务人员（劳务公司、班组、工种、机构）选择功能  lb_peoplefunction_edit.html------------------*/

var companytableurl = laborport + "/LabourCompanyController/findByPage"; //查询劳务公司信息
var teamtableurl = laborport + "/LabourTeamController/findByPage"; //查询班组信息
var jobtableurl = laborport + "/LabourJobController/findByPage"; //查询工种信息
var companyurl = laborport + "/LabourController/update"; //修改劳务人员的劳务公司信息 
var ckeckedurl = laborport + "/LabourController/selectById";//查询人员信息

var labourid = $.cookie("labourid");
var editcookie = $.cookie("nav");
var Wtid = JSON.parse(editcookie).w;

//页面companytable渲染
var tablecompanyget = (function() {
	$.post(companytableurl, {
			'pageNo': 1,
			'pageSize': 100,
		},
		function(result) {
			var code = result.code;
			var list = result.object;
			if(code == 0) {
				var ant = list.total;
				antrows = ant; //将查询结果总数变成全局变量
				$('.totalNum').text(ant);
				$.each(list.list, function(idx, obj) {
					var idx = idx + 1; //排序默认从0开始，idx将作为显示题号，因此+1
					var id = obj.companyid;
					var Qhtml =
						'<tr id="' + obj.companyid + '">\
          <td>\
            <div class="layui-unselect layui-form-checkbox ' + obj.companyid + '" lay-skin="primary" data-id="' + obj.companyid + '">\
              <i class="layui-icon">&#xe605;</i>\
            </div>\
          </td>\
          <td>' + idx + '</td>\
          <td>' + obj.name + '</td>\
           <td>' + obj.addr + '</td>\
        </tr>';
					$("#lb_company").append(Qhtml);
					var addckecked = (function(id) {
						console.log(labourid);
						$.post(ckeckedurl, {
							labourId: labourid,
						}, function(result) {
							var code = result.code;
							var jurisdiction = result.object;
							if(code == 0) {
									if(id == jurisdiction.companyid) {
										$("." + id).addClass("layui-form-checked");
									}
							}
						})
					});
					addckecked(id);
				});
			} else {
				alert('您的登录认证已失效，请重新登录！');
			};
			tableCheck.init();
		}, 'JSON');
});
tablecompanyget();

//选择劳务公司
function companyAll(argument) {
	tableCheck.getData();
	var data = $("#lb_company .layui-form-checked").attr("data-id");//单选
	var value = JSON.stringify(data);
	value = value.replace('[', '');
	value = value.replace(']', '');
	value = value.replace(/\"/g, ''); //去掉字符串中的英文引号
	layer.confirm('确定为该角色授予此权限?'+value, function(index) {
		$.post(companyurl, {
			'labourid': labourid,
			'companyid': value,
		}, function(result) {
			console.log(value, data);
			var code = result.code;
			if(code == 0) {
				layer.msg('授权成功!', {
					icon: 1,
					time: 1000
				}, function() {
					//关闭当前frame
					parent.layer.close(index);
				});
			} else {
				layer.msg('error!请重新选择一个劳务公司', {
					icon: 2,
					time: 1000
				}, function() {
					//关闭当前frame
					//parent.layer.close(index);
				});
			}
		})
	});
}


//页面teamtable渲染
var tableteamget = (function() {
	$.post( teamtableurl, {
			'pageNo': 1,
			'pageSize': 100,
		},
		function(result) {
			var code = result.code;
			var list = result.object;
			if(code == 0) {
				var ant = list.total;
				antrows = ant; //将查询结果总数变成全局变量
				$('.totalNum').text(ant);
				$.each(list.list, function(idx, obj) {
					var idx = idx + 1; //排序默认从0开始，idx将作为显示题号，因此+1
					var id = obj.teamid;
					var Qhtml =
						'<tr id="' + obj.teamid + '">\
          <td>\
            <div class="layui-unselect layui-form-checkbox ' + obj.teamid + '" lay-skin="primary" data-id="' + obj.teamid + '">\
              <i class="layui-icon">&#xe605;</i>\
            </div>\
          </td>\
          <td>' + idx + '</td>\
          <td>' + obj.teamname + '</td>\
           <td>' + obj.description + '</td>\
        </tr>';
					$("#lb_team").append(Qhtml);
					var teamckecked = (function(id) {
						console.log(labourid);
						$.post(ckeckedurl, {
							labourId: labourid,
						}, function(result) {
							var code = result.code;
							var team = result.object;
							if(code == 0) {								
									if(id ==team.teamid) {
										$("." + id).addClass("layui-form-checked");
									}
									
							}
						})
					});
					teamckecked(id);
				});
			} else {
				alert('您的登录认证已失效，请重新登录！');
			};
			tableCheck.init();
		}, 'JSON');
});
tableteamget();

//选择班组
function teamAll(argument) {
	tableCheck.getData();
	var data = $("#team_job .layui-form-checked").attr("data-id");//单选
	var value = JSON.stringify(data);
	value = value.replace('[', '');
	value = value.replace(']', '');
	value = value.replace(/\"/g, ''); //去掉字符串中的英文引号
	layer.confirm('确定为该角色授予此权限?'+value, function(index) {
		$.post(companyurl, {
			'labourid': labourid,
			'teamid': value,
		}, function(result) {
			console.log(value, data);
			var code = result.code;
			if(code == 0) {
				layer.msg('授权成功!', {
					icon: 1,
					time: 1000
				}, function() {
					//关闭当前frame
					parent.layer.close(index);
				});
			} else {
				layer.msg('error!请重新选择一个班组', {
					icon: 2,
					time: 1000
				}, function() {
					//关闭当前frame
					//parent.layer.close(index); 
				});
			}
		})
	});
}

//页面jobtable渲染
var tablejobget = (function() {
	$.post(jobtableurl, {
			'pageNo': 1,
			'pageSize': 100,
		},
		function(result) {
			var code = result.code;
			var list = result.object;
			if(code == 0) {
				var ant = list.total;
				antrows = ant; //将查询结果总数变成全局变量
				$('.totalNum').text(ant);
				$.each(list.list, function(idx, obj) {
					var idx = idx + 1; //排序默认从0开始，idx将作为显示题号，因此+1
					var id = obj.jobid;
					var Qhtml =
						'<tr id="' + obj.jobid + '">\
          <td>\
            <div class="layui-unselect layui-form-checkbox ' + obj.jobid + '" lay-skin="primary" data-id="' + obj.jobid + '">\
              <i class="layui-icon">&#xe605;</i>\
            </div>\
          </td>\
          <td>' + idx + '</td>\
          <td>' + obj.jobname + '</td>\
           <td>' + obj.description + '</td>\
        </tr>';
					$("#lb_job").append(Qhtml);
					var teamckecked = (function(id) {;
						$.post(ckeckedurl, {
							labourId: labourid,
						}, function(result) {
							var code = result.code;
							var job = result.object;
							if(code == 0) {								
									if(id ==job.jobid) {
										$("." + id).addClass("layui-form-checked");
									}
									
							}
						})
					});
					teamckecked(id);
				});
			} else {
				alert('您的登录认证已失效，请重新登录！');
			};
			tableCheck.init();
		}, 'JSON');
});
tablejobget();

//选择工种
function jobAll(argument) {
	tableCheck.getData();//启动checkbox点击事件
	var data = $("#lb_job .layui-form-checked").attr("data-id");//单选
	var value = JSON.stringify(data);
	value = value.replace('[', '');
	value = value.replace(']', '');
	value = value.replace(/\"/g, ''); //去掉字符串中的英文引号
	layer.confirm('确定为该角色授予此权限?'+value, function(index) {
		$.post(companyurl, {
			'labourid': labourid,
			'jobid': value,
		}, function(result) {
			console.log(value, data);
			var code = result.code;
			if(code == 0) {
				layer.msg('授权成功!', {
					icon: 1,
					time: 1000
				}, function() {
					//关闭当前frame
					parent.layer.close(index);
				});
			} else {
				layer.msg('error，请重新一个工种!', {
					icon: 2,
					time: 1000
				}, function() {
					//关闭当前frame
					//parent.layer.close(index); 
				});
			}
		})
	});
}


//面板显隐
$(".x-nav .layui-breadcrumb a").click(function(){
	var id = $(this).attr("id");
	$(".x-body").css("display","none");
	$("#"+id+"_plane").css("display","block");
})